package com.chengqj.userserverprovider.controller;

import com.chengqj.user.server.dto.*;
import com.chengqj.user.server.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping(value = "/login")
    public UserLoginResponse login(){
        UserLoginRequest request = new UserLoginRequest();
        request.setUserName("userName");
        request.setPassword("password");
        UserLoginResponse response = userService.login(request);
        return response;
    }
    @GetMapping(value = "/checkAuth/{token}")
    public CheckAuthResponse checkAuth(@PathVariable String token){
        CheckAuthRequest request = new CheckAuthRequest();
        request.setToken(token);
        CheckAuthResponse response = userService.checkAuth(request);
        return response;
    }
    @GetMapping(value = "/register")
    public UserRegisterResponse register(String userName,String password){
        UserRegisterRequest userRegisterRequest = new UserRegisterRequest();
        userRegisterRequest.setUserName(userName);
        userRegisterRequest.setPassword(password);
        UserRegisterResponse response = userService.register(userRegisterRequest);
        return response;
    }

    public IUserService getUserService() {
        return userService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }
}
